package business;

import utils.GeneralUtils;

public class ConnectionThread extends Thread {
	private Connection connection;
	private MessageReceiver receiver;

	public ConnectionThread(Connection connection, MessageReceiver receiver) {
		this.connection = connection;
		this.receiver = receiver;
	}

	@Override
	public void run() {
		while (true) {
			if (connection.isConnected()) {
				String text = connection.receiveText();
				GeneralUtils.println(text);
				receiver.setMessage(MessageHandler.convertTextToMessage(text));
			} else {
				break;
			}
		}

	}

}
